package util;
import cn.hutool.core.util.StrUtil;
import com.google.common.collect.Maps;
import java.io.InputStream;
import java.util.Map;
import java.util.Properties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.ClassPathResource;

public final class CommonUtils {
    private static final Logger logger = LoggerFactory.getLogger(CommonUtils.class);
    private static final Map<String, Properties> PROPERTIES_MAP = Maps.newConcurrentMap();
    private static final String DEFAULT_PROPERTIES_FILE_NAME = "config.properties";
    private static final String LOGIN_SSL_FLAG = "on";

    public CommonUtils() {
    }

    public static Properties getProperties(String propertiesPath) {
        Properties properties = new Properties();

        try {
            InputStream in = (new ClassPathResource(propertiesPath)).getInputStream();
            properties.load(in);
            PROPERTIES_MAP.put(propertiesPath, properties);
            return properties;
        } catch (Exception var3) {
            logger.error("加载配置文件出错！", var3);
            throw new RuntimeException("加载配置文件出错！");
        }
    }

    public static String getDefaultConfig(String key) {
        return getConfig("config.properties", key);
    }

    public static String getDefaultConfig(String key, String defaultValue) {
        return getConfig("config.properties", key, defaultValue);
    }

    public static String getConfig(String configFileName, String key) {
        try {
            return PROPERTIES_MAP.containsKey(configFileName) ? ((Properties)PROPERTIES_MAP.get(configFileName)).getProperty(key) : getProperties(configFileName).getProperty(key);
        } catch (Exception var3) {
            logger.error(var3.getMessage(), var3);
            return "";
        }
    }

    public static String getConfig(String configFileName, String key, String defaultValue) {
        try {
            return PROPERTIES_MAP.containsKey(configFileName) ? ((Properties)PROPERTIES_MAP.get(configFileName)).getProperty(key, defaultValue) : getProperties(configFileName).getProperty(key, defaultValue);
        } catch (Exception var4) {
            logger.error(var4.getMessage(), var4);
            return "";
        }
    }

    public static boolean isLoginSSLon() {
        return StrUtil.equalsIgnoreCase("on", getDefaultConfig("sslLogin"));
    }

    public static String getSslLoginType() {
        return getDefaultConfig("sslLoginType", "rsa");
    }
}
